﻿/**************************************************************************
Copyright: 赵旭
Author: 赵旭
Date: 2020-06-24
Description: 自定义按钮
                QGroupButton: 按钮中有图标和文字
**************************************************************************/
#ifndef QGroupButton_H
#define QGroupButton_H

#include "QCommonWidgets_global.h"
#include <QPushButton>

QCOMMWIDGETS_BEGIN_NAMESPACE


/*
*Summary:按钮中有图标和文字
*/
class QCOMMONWIDGETS_EXPORT QGroupButton : public QToolButton
{
    Q_OBJECT
public:
    // 图标和文字排列方向
    enum EOrientation
    {
        e_onlyIcon = 0,           // 只有图标
        e_onlyText,               // 只有文字
        e_textBesideIcon,         // 左图标右文字
        e_textUnderIcon,          // 上图标下文字
    };
public:
    QGroupButton(const QString &strIcon, const QString &strText, EOrientation orientation = e_textBesideIcon, QWidget *parent = 0);
	QGroupButton(const QString &strIcon, QWidget *parent = 0);
    QGroupButton(const QIcon &icon, const QString &strText, EOrientation orientation = e_textBesideIcon, QWidget *parent = 0);
    QGroupButton(const QIcon &icon, const QString &strText,QFont font, QColor color, EOrientation orientation = e_textBesideIcon, QWidget *parent = 0);
    virtual ~QGroupButton();

    void setButtonHeight(int height);

private:
    void initUI(const QIcon &icon, const QString &strText, EOrientation orientation);

protected slots:
    virtual void slotClicked(){}  // 点击按钮

signals:
    void signClicked();          // 这个信号只有在松开时光标仍在按钮时候才会发送

protected:
    virtual void mousePressEvent(QMouseEvent *e);
    virtual void mouseReleaseEvent(QMouseEvent *e);
private:
    bool  m_bPressed;            // 鼠标是否在按钮内按下
};


class QCOMMONWIDGETS_EXPORT QTextButton : public QToolButton
{
    Q_OBJECT
public:
    QTextButton(const QString str, QWidget *parent = nullptr, const QColor colorNormal = QColor(), const QColor colorHover = QColor(), const QColor colorPressed = QColor());
    virtual ~QTextButton();

protected:
    virtual void mousePressEvent(QMouseEvent *e);
    virtual void mouseReleaseEvent(QMouseEvent *e);

signals:
    void signClicked();          // 这个信号只有在松开时光标仍在按钮时候才会发送

private:
    bool  m_bPressed;            // 鼠标是否在按钮内按下
};


QCOMMWIDGETS_END_NAMESPACE

#endif // QBUTTONBASE_H
